﻿using Avalonia.Exusiai.Editor.ViewModels;
using Avalonia.Exusiai.Editor.Views;
using Core.ECS;
using Core.Tools;
using System.ComponentModel;
using System.Diagnostics;

namespace Avalonia.Exusiai.Editor.ViewModels;

public class GlobalData : INotifyPropertyChanged
{
    private GlobalData()
    { }
    public static GlobalData Instance { private set; get; } = new GlobalData();
    public event PropertyChangedEventHandler? PropertyChanged;
    public Scene? Scene
    {
        get => _scene;
        set
        {
            _scene = value;
        }
    }
    private Scene? _scene = null;
    private string? _selectedFolder="C://";
    public string? SelectedFolder
    {
        get => _selectedFolder;
        set
        {
            if (_selectedFolder == value) return;
            _selectedFolder = value;
            if(value != null)
            {
                value += "/scene.xml";
                SerializeHelper.Deserialize(value, out _scene);
            }
            if(_scene != null)
            {
                foreach (var actor in _scene.ActorsList)
                {
                    actor.Transform.UpdateParent();
                }
                SceneHierarchyViewModel.UpdateSceneTree();
            }
            PropertyChanged?.Invoke(null,
                new PropertyChangedEventArgs(nameof(SelectedFolder)));
        }
    }
}